from models.PrevenCureWikiSubSysModels import Speices,Disease
from utils.dataBase import db_session
from random import randint
#增加
def add():
    add= []
    speices1 = Speices('name{}'.format(randint(0,10)),'info','栽培技术')
    add.append(speices1)
    speices2 = Speices('name{}'.format(randint(0, 10)), 'info', '栽培技术')
    add.append(speices2)
    speices3 = Speices('name{}'.format(randint(0, 10)), 'info', '栽培技术')
    add.append(speices3)
    speices4 = Speices('name{}'.format(randint(0, 10)), 'info', '栽培技术')
    add.append(speices4)

    disease1 = Disease('name{}'.format(randint(0,100)),'info','治疗方法','防治方法',1)
    add.append(disease1)
    disease2 = Disease('name{}'.format(randint(0, 100)),'info','治疗方法','防治方法',1)
    add.append(disease2)
    disease3 = Disease('name{}'.format(randint(0, 100)),'info','治疗方法','防治方法',1)
    add.append(disease3)
    disease4 = Disease('name{}'.format(randint(0, 100)),'info','治疗方法','防治方法',1)
    add.append(disease4)
    for i in add:
        print(i)
    db_session.add_all(add)
    db_session.commit()

#删除查询
def delete():
    speices = Speices.query.all()
    print('删除：',speices[2])
    db_session.delete(speices[2])

    disease = Disease.query.all()
    print('删除:',disease[2])
    db_session.delete(disease[2])

    db_session.commit()

#修改
def update():
    speices = Speices.query.all()
    u2 = speices[0]
    u2.sname='修改'

    diseases = Disease.query.all()
    uc2 = diseases[0]
    uc2.dname = '修改'

    db_session.commit()

"""
测试时间：2020.3.26
测试结果：全部通过
"""
if __name__ == '__main__':
    # add()
    # delete()
    update()